package main

import (
	"fmt"
	"google.golang.org/grpc"
	"net/http"
	"webdemo/src/grpc/helper"
	"webdemo/src/grpc/service"
)

func main() {

	// 使用证书
	certs := helper.GetServerCerts()
	rpcServer := grpc.NewServer(grpc.Creds(certs))

	//rpcServer := grpc.NewServer()
	service.RegisterProductServiceServer(rpcServer, new(service.ProductService))

	/*
		listen, err := net.Listen("tcp", ":8081")
		if err != nil {
			logging.Error("net.Listen error ", err)
			return
		}

		err = rpcServer.Serve(listen)
		if err != nil {
			logging.Error("rpcServer.Serve", err)
			return
		}*/

	mux := http.NewServeMux()
	mux.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Println(request)
		rpcServer.ServeHTTP(writer, request)
	})
	httpServer := &http.Server{
		Addr:    ":8081",
		Handler: mux,
	}
	//https://127.0.0.1:8081
	httpServer.ListenAndServeTLS("src/grpc/cert/server.pem", "src/grpc/cert/server.key")

}
